import EditorOptions from '../types/editorOptions.ts'
import { onBeforeUnmount, onMounted, shallowRef } from 'vue'

import Editor from '../extend/core.ts'

export const useEditor = (options: EditorOptions) => {
  const editor = shallowRef<Editor>()

  onMounted(() => {
    editor.value = new Editor(options)
  })

  onBeforeUnmount(() => {
    editor.value?.destroy()
  })

  return editor
}
